package cn.lg.soar.system.biz.modules.auth.client;

import cn.lg.soar.common.util.token.LoginInfo;
import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.system.api.constant.ModuleConst;
import cn.lg.soar.system.api.model.TokenInfoDTO;
import cn.lg.soar.system.api.service.ILoginApi;
import cn.lg.soar.system.biz.modules.monitor.service.IRefreshTokenService;
import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author luguoxiang
 * @date 2022/1/3
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Hidden
@ApiClient("boot")
@RestController
@RequestMapping(ModuleConst.CLIENT_PATH + "/login")
public class LoginApiClient implements ILoginApi {

    @Autowired
    private IRefreshTokenService service;

    @PostMapping("login1")
    @Override
    public TokenInfoDTO login(@RequestBody LoginInfo loginInfo, @RequestParam("refreshExpires") long refreshExpires) {
        return service.create(loginInfo, refreshExpires);
    }

    @PostMapping("login2")
    @Override
    public TokenInfoDTO login(@RequestBody LoginInfo loginInfo, @RequestParam("rememberMe") boolean rememberMe) {
        return service.create(loginInfo, rememberMe);
    }

    @GetMapping("logoutByTokenId")
    @Override
    public void logoutByTokenId(@RequestParam("tokenId") Long tokenId) {
        service.removeById(tokenId);
    }

    @GetMapping("logout1")
    @Override
    public void logout(@RequestParam("userId") Long userId) {
        service.removeByUserId(userId);
    }

    @GetMapping("logout2")
    @Override
    public void logout(@RequestParam("userId") Long userId, @RequestParam("clientType") Integer clientType) {
        service.removeByUserId(userId, clientType);
    }

}
